package com.gwtjs.icustom.controller.manager;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gwtjs.icustom.entity.ResultWrapper;
import com.gwtjs.icustom.mapper.AppMapper;
import com.gwtjs.icustom.pojo.App;

@RestController @RequestMapping("/app")
public class ManagerAppController {

	@Autowired
	private AppMapper appMapper;
	private final static Logger logger = LoggerFactory.getLogger(ManagerUserController.class);

	@GetMapping("/get/{id}")
	public ResultWrapper queryUserById(@PathVariable("id") Integer id) {
		App app = appMapper.queryAppById(id);
		return ResultWrapper.constructSuccessResult(app);

	}

	@GetMapping("/get_{appName}")
	public ResultWrapper queryAppName(@PathVariable("appName") String appName) {
		App app = appMapper.queryAppName(appName);
		return ResultWrapper.constructSuccessResult(app);

	}

	@GetMapping("/get/list")
	public ResultWrapper queryAppStatusList() {
		return this.queryAppList(null);
	}

	@GetMapping("/get/list/{appType}")
	public ResultWrapper queryAppList(@PathVariable("appType") String appType) {
		App app = null;
		if(appType!=null) {
			app = new App();
			app.setAppType(appType);
		}
		List<App> appList = appMapper.queryAppList(app);
		logger.info("query App List......");
		
		return ResultWrapper.successResult(appList);
	}

	@DeleteMapping("/del")
	public ResultWrapper delApps(@RequestBody List<App> records) {
		appMapper.deleteApps(records);
		return ResultWrapper.constructSuccessResult(records);

	}

	@PostMapping("/add")
	public ResultWrapper addApps(@RequestBody List<App> records) {
		for (App app : records) {
			appMapper.addApp(app);
		}
		return ResultWrapper.constructSuccessResult(records);

	}

}
